home *** CD-ROM | disk | FTP | other *** search
- /* interlace fields from uosat pics and make even number of pixels per line.
-
- 21JUL91 NK6K
-
- This program takes a UoSAT-5 CCD 2-field image and interlaces them into
- one flat raster file. It also adds a 0 pixel to the end of each line,
- the rg8 program used to convert the raster file to .GIF doesn't like
- odd line lengths when using the /2 option.
-
- Suggested usage:
-
- inter ccdn ccdni
- rg8 ccdni. /c612 /r578
-
- Harold
-
- Added 7/28/91
- Remove first four bytes from file, this avoids the wrap-around effect.
-
-
- Note: Some early image files on UO-22 had missing or duplicate blocks,
- this will cause this program to emit an incorrect raster file.
-
- From UoSAT:
-
- The data format that will be used to transfer image data from the
- transputer to the OBC is described as follows.
-
- The image frame is composed of two interleaved fields of 288 lines by 611
- pixels each, combined to give a total image of 576 by 611. The total
- length of an image file is 352048 bytes, with the extra bytes due to the
- positional offset between the two fields.
-
- When reading the file, the first byte corresponds to the grey level of the
- top leftmost pixel. The follow bytes define the pixels to the right of
- the first one until the end of the first line is reached. Subsequent
- lines are aligned below this one for the rest of the first field (i.e.
- line 288).
-
- Line 289 is the first line in the second field. At this point 355 bytes
- (i.e. half a line) must be read and discarded to ensure that the two
- fields align properly.
-
- Because the two fields are interlaced, the lines in the second field must
- be placed in between the lines of the first field as shown below. This
- implies that when the first field is displayed, adequate room must be left
- for the insertion of the second field.
-
- When a full frame is displayed the arrangement of the lines should be:
-
- Line 1
- Line 289
- Line 2
- Line 290
- Line 3
- ....
- ....
- Line 574
- Line 287
- Line 575
- Line 288
- Line 576.
-
- */
- #include <stdio.h>
- #include <dos.h>
- #include <fcntl.h>
- #include <sys\types.h>
- #include <sys\stat.h>
-
- #define LINE_SIZE 611
- #define NUM_LINE_FIELD 288
-
-
- long start_field_2;
- int lines=0;
- int skip_lines=0;
-
- char buff[LINE_SIZE+1];
- int fillval=0;
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
-
- int fi1,fi2,fo;
- int i;
-
- start_field_2 = ((long)LINE_SIZE*(long)NUM_LINE_FIELD)+355l;
-
-
- if (argc<2) {
- printf ("usage: inter input output [skip_lines]\n");
- printf ("skip - number of lines from start of image to not\n");
- printf ("include in the output file");
- exit(1);
- }
-
- if (argc>3) skip_lines = atoi(argv[3]);
-
- if ((fi1= open(argv[1], O_BINARY)) == -1){
- printf("cannot open: %s\n",argv[1]);
- perror("On input file");
- exit(1);
- }
-
- if ((fi2= open(argv[1], O_BINARY)) == -1){
- printf("cannot open: %s\n",argv[1]);
- perror("On input file");
- exit(1);
- }
-
- lseek(fi2,start_field_2+4l,SEEK_SET);
- lseek(fi1,4l,SEEK_SET);
-
-
- if ((fo = open(argv[2], 0)) != -1){
- printf("output file exists. Aborted\n");
- exit(1);
- }
-
- if ((fo = open(argv[2],O_CREAT | O_TRUNC | O_BINARY | O_RDWR, S_IREAD | S_IWRITE)) == -1) {
- printf("cannot open: %s\n",argv[2]);
- perror("On output file");
- exit(1);
- }
-
-
- buff[LINE_SIZE+1]=0;
- for (i=0;i<NUM_LINE_FIELD;i++) {
-
- /* If file is short, fill with zeroes */
- memset(buff,0,LINE_SIZE+1);
- if (read(fi1, buff, LINE_SIZE)==-1) {
- perror("On input file 1st field\n");
- exit(1);
- }
- if (lines >= skip_lines) {
- if (write(fo,buff,LINE_SIZE+1)==-1) {
- perror("On output file 1st field\n");
- exit(1);
- }
- }
-
- memset(buff,0,LINE_SIZE+1);
- if (read(fi2, buff, LINE_SIZE)==-1) {
- perror("On input file 2nd field\n");
- exit(1);
- }
-
- if (lines >= skip_lines) {
- if (write(fo,buff,LINE_SIZE+1)==-1) {
- perror("On output file 2nd field\n");
- exit(1);
- }
- }
- lines++;
- }
- close (fo);
- close (fi1);
- close (fi2);
-
- }
-